package org.qloudgen.borg.pages.panel;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.wicket.markup.html.form.Button;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.FormComponent;
import org.apache.wicket.markup.html.form.RequiredTextField;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.CompoundPropertyModel;
import org.apache.wicket.request.mapper.parameter.PageParameters;
import org.qloudgen.borg.CommonValues;
import org.qloudgen.borg.beans.AppBean;
import org.qloudgen.borg.beans.FileUploadBean;
import org.qloudgen.borg.beans.FuncBean;
import org.qloudgen.borg.beans.KeyValue;
import org.qloudgen.borg.metadb.DefaultImpl;
import org.qloudgen.borg.pages.AppFuncListPage;
import org.qloudgen.borg.pages.common.BasePage;
import org.qloudgen.borg.pages.panel.FileUploadPanel;

@SuppressWarnings({ "unused","rawtypes"})
public class AppFuncPanel extends Panel {
	
	/**
	 * @Author youngeryoyo
	 * youngeryoyo@gmail.com
	 */
	static Log log = LogFactory.getLog(AppFuncPanel.class);
	
	private static final long serialVersionUID = 1L;
	private transient FuncBean func;
	
	public AppFuncPanel(String id , final FuncBean func){
		
		super(id);

		Form form = new Form("form"){
			
			private static final long serialVersionUID = 1L;
			protected void onSubmit() {
				FuncBean obj = (FuncBean)getDefaultModelObject();
				func.setFuncName(obj.getFuncName());
				func.setFuncDesc(obj.getFuncDesc());
				func.setTableFile(obj.getTableFile());
				func.setHandlerFile(obj.getHandlerFile());
			}
			
		};
		this.add(form);
	
		final FileUploadPanel tablePanel = new FileUploadPanel("tablePanel","模型创建脚本：", func , "tableFile");		
		final FileUploadPanel handlerPanel = new FileUploadPanel("handlerPanel","功能处理脚本：" , func, "handlerFile");

		form.setDefaultModel(new CompoundPropertyModel<FuncBean>(func));
		
		TextField<String> app = new TextField<String>("appName");
		if (func.getAppName() != null ) app.setEnabled(false);
		form.add(app);
		
		form.add(new RequiredTextField<String>("funcName"));
		form.add(new TextField<String>("funcDesc"));
		form.add(new RequiredTextField<String>("tableName"));

		form.add(tablePanel);
		form.add(handlerPanel);
		
		form.add(new Button("save"));
	}

}
